package day13.Eat;

import java.util.concurrent.ArrayBlockingQueue;

public class ZongHe {
    public static void main(String[] args) {
        ArrayBlockingQueue<String> list = new ArrayBlockingQueue<>(1);
        Foodie2 f = new Foodie2(list);
        Cooker2 c = new Cooker2(list);
        f.start();
        c.start();
    }
}

class Foodie2 extends Thread {
    private ArrayBlockingQueue<String> bd;
    public Foodie2(ArrayBlockingQueue<String> list) {
        this.bd = list;
    }

    @Override
    public void run() {
        while (true) {
            try {
                String take = bd.take();
                System.out.println("吃货将" + take + "拿出来吃了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Cooker2 extends Thread {
    private ArrayBlockingQueue<String> bd;
    public Cooker2(ArrayBlockingQueue<String> list) {
        this.bd = list;
    }

    @Override
    public void run() {
        while (true) {
            try {
                bd.put("汉堡包");
                System.out.println("厨师放进去了一个汉堡包");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
